#include "BlockStrengthenPlugin.h"
#include "Expand/PluginsManager.h"
#include "Managers/BlocksManager.h"

#include "GameSingleton.h"
#include "Log.h"
#include <cfloat>

#include "Blocks/GrassBlock.h"
#include "Blocks/PlanksBlock.h"
#include "Blocks/FramedGlassBlock.h"
#include "Blocks/ChestBlock.h"
#include "Blocks/WoodenStairsBlock.h"
#include "Blocks/WoodenSlabBlock.h"
#include "Blocks/WindowBlock.h"
#include "Blocks/MarbleBlock.h"
#include "Blocks/MarbleStairsBlock.h"
#include "Blocks/MarbleSlabBlock.h"
#include "Blocks/MalachiteBlock.h"
#include "Blocks/DiamondBlock.h"

namespace BlockStrengthen
{
    BlockStrengthenPlugin::BlockStrengthenPlugin() {}

    const std::string &BlockStrengthenPlugin::getPluginName()
    {
        static const std::string pluginName = "方块强化";
        return pluginName;
    }

    const std::string &BlockStrengthenPlugin::getIntroduce()
    {
        static const std::string introduce = "方块强化，加强的方块不会被击毁，不会被爆破，不会燃烧，能阻挡流体";
        return introduce;
    }

    void BlockStrengthenPlugin::strengthen(int32_t blockContents)
    {
        Block *block = GameSingleton::blocksManager->blocks[blockContents];
        if(block != nullptr)
        {
            block->ProjectileResilience = 1.0f;         // 不会被击毁
            block->ExplosionResilience = FLT_MAX;       // 不会被炸毁
            block->IsFluidBlocker = true;               // 不会被流体冲掉
            block->FireDuration = 0.0f;                 // 不会着火
        }
        else
        {
            Log::Warn(fmt::format("[方块强化]要强化的方块 {} 不存在", blockContents));
        }
    }

    void BlockStrengthenPlugin::load()
    {
        strengthen(GrassBlock::Index());                // 玻璃
        strengthen(PlanksBlock::Index());               // 木板
        strengthen(FramedGlassBlock::Index());          // 玻璃框
        strengthen(ChestBlock::Index());                // 箱子
        strengthen(WoodenStairsBlock::Index());         // 木台阶
        strengthen(WoodenSlabBlock::Index());           // 半木板
        strengthen(WindowBlock::Index());               // 窗户
        strengthen(MarbleBlock::Index());               // 大理石
        strengthen(MarbleStairsBlock::Index());         // 大理石台阶
        strengthen(MarbleSlabBlock::Index());           // 大理石半砖
        strengthen(DiamondBlock::Index());              // 钻石块
    }

    uint32_t BlockStrengthenPlugin::getUseAuthLevel()
    {
        return 100;
    }

    AuthDisplayType BlockStrengthenPlugin::getDisplayType()
    {
        return AuthDisplayType::Authority;
    }

    void BlockStrengthenPlugin::processCmd(ChatObj &chatObj, std::vector<std::string> &cmdDataVec) {}

} // namespace PocketSurvival

extern "C" void initialize()
{
    GameSingleton::pluginsManager->registerPlugin<BlockStrengthen::BlockStrengthenPlugin>();
    Log::Info("成功加载 方块强化 插件");
}